package com.heima.article.listener;

import com.heima.article.mapper.ApArticleMapper;
import com.heima.model.article.pojos.ApArticle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author JianKang
 * @create 2023-11-06 20:36
 */
@Component
public class ArticleDateListener {

    @Autowired
    ApArticleMapper apArticleMapper;

    @KafkaListener(topics = "article-comment-add")
    public void articleCommentAdd(String message) {
        ApArticle apArticle = apArticleMapper.selectById(Long.parseLong(message));
        if (apArticle != null) {
            apArticle.setComment(apArticle.getComment() + 1);
            apArticleMapper.updateById(apArticle);
        }
        System.out.println(message);
    }
}
